const Mock = require("mockjs");
const Random = Mock.Random;
const getQuestionList = require("./data/getQuestionList");
const { response } = require("express");
const getComponentList= require('./data/getComponentList')
module.exports = [
  {
    //获取单个问卷信息
    url: "/api/question/:id",
    method: "get",
    response() {
      return {
        errno: 0,
        data: {
          id: Random.id,
          title: Random.cname(),
          desc:'问卷描述',
          js:'',
          css:'',
          isPublished:true, //是否发布
          isDeleted:false,
          //组件列表属性
          componentList: getComponentList()
        },
        // errno:1002,
        // msg:'错误测试'
      };
    },
  },
  {
    //创建问卷
    url: "/api/question",
    method: "post",
    response() {
      return {
        errno: 0,
        data: {
          id: Random.id(),
        },
      };
    },
  },
  {
    //获取问卷列表（查询）
    url: "/api/question",
    method: "get",
    headers: { "Content-Type": "application/json" },
    response(ctx) {
      const { url = "", query = {} } = ctx;

      const isDeleted = url.indexOf("isDeleted=true") >= 0;
      const isStar = url.indexOf("isStar=true") >= 0;
      const pageSize = parseInt(query.pageSize) || 10;
      // const isStar=true
      // const isDeleted=true
      // const pageSize=15
      return {
        errno: 0,
        data: {
          list: getQuestionList({ len: pageSize, isStar, isDeleted }),
          total: 100, //总数 用于分页
        },
      };
    },
  },
  {
    //更新问卷信息
    url: "/api/question/:id",
    method: "patch",
    response() {
      return {
        errno: 0,
      };
    },
  },
  {
    //复制问卷
    url: "/api/question/duplicate/:id",
    method: "post",
    response() {
      return {
        errno: 0,
        data: {
          id: Random.id(),
        },
      };
    },
  },
  {
    //批量彻底删除问卷
    url: "/api/question",
    method: "delete",
    response() {
      return {
        errno: 0,
      };
    },
  },
];
